<?php
class Model_TagArticle_TagArticle extends Model_System {
	public $_name = "tag_article";
	protected $_sequence = true;
	public function getAll() {
		$result = $this->select();
		return $this->fetchAll($result)->toArray();
	}
	public function getItemId($id){
		$result = $this->select();
		$result->where('id = ?',$id);
		return $this->fetchRow($result)->toArray();
	}
	public function getItemsByArticle($id){
		$result = $this->select();
		$result->where('article = ?',$id);
		return $this->fetchAll($result)->toArray();
	}
	public function getItemsByTag($id){
		$result = $this->select();
		$result->where('tag = ?',$id);
		return $this->fetchAll($result)->toArray();
	}
	public function insertItem($data)
	{
		try {
		    $this->insert($data);
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
		
	}
	public function updateItem($data,$id){
		try {
		    $this->update($data, "id = $id");
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
	}
}